// 计算4分位
const getQuartile = (data: any[], percentile: number) => {
  const sortedData = data.slice().sort((a: number, b: number) => a - b);
  const index = (sortedData.length - 1) * percentile;
  const lower = Math.floor(index);
  const upper = Math.ceil(index);
  if (lower === upper) {
    return sortedData[lower].toFixed(2);
  } else {
    const interpolation = index - lower;
    const result = sortedData[lower] * (1 - interpolation) + sortedData[upper] * interpolation;
    return result.toFixed(2);
  }
};
export const processBoxPlotData = (data: any[]) => {
  const boxPlotData = data.map((row: any) => {
    const min = Math.min(...row).toFixed(2);
    const q1 = getQuartile(row, 0.25);
    const median = getQuartile(row, 0.5);
    const q3 = getQuartile(row, 0.75);
    const max = Math.max(...row).toFixed(2);
    return [min, q1, median, q3, max];
  });
  return boxPlotData;
};

// 字体自适应方法
export const pxToRem = (px: number) => {
  const scale = document.documentElement.clientWidth / 1920;
  return Math.round(px * Math.min(scale, 3));
};

// 获取随机颜色
export const getRandomColor = () => {
  // 生成随机的 R、G、B 分量
  var r = Math.floor(Math.random() * 256);
  var g = Math.floor(Math.random() * 256);
  var b = Math.floor(Math.random() * 256);
  // 将 RGB 转换为十六进制表示
  var color = "#" + r.toString(16).padStart(2, '0') + g.toString(16).padStart(2, '0') + b.toString(16).padStart(2, '0');
  return color;
}


